home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group02b.txt / 000086_icon-group-sender_Wed Oct 23 16:27:29 2002.msg < prev    next >
Internet Message Format  |  2003-01-02  |  1KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id g9NNR0g29135
  4.     for icon-group-addresses; Wed, 23 Oct 2002 16:27:01 -0700 (MST)
  5. Message-Id: <200210232327.g9NNR0g29135@baskerville.CS.Arizona.EDU>
  6. From: "Paul W. Abrahams" <abrahams@acm.org>
  7. To: icon-group@cs.arizona.edu
  8. Subject: move_corresponding: the procedure
  9. Date: Wed, 23 Oct 2002 16:32:23 -0400
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11. Status: RO
  12.  
  13. Here's the code of the move_corresponding procedure I referred to earlier 
  14. (which, according to Clint, will work only in newer versions of Icon).   It 
  15. might be a useful addition to the Icon library.
  16.  
  17. Paul
  18.  
  19. -----------------------
  20.  
  21. procedure move_corresponding(s1,s2)
  22.  
  23. # move_corresponding moves correspondingly-named fields from the
  24. # record parameter s1 to the record parameter s2.  Fields whose
  25. # names are not common are not affected.  The ordering of the field
  26. # names is irrelevant.
  27.  
  28. local names1,names2,n,i
  29.  
  30. # Generate the set of common names
  31.  
  32. names1:=set()
  33. every i := 1 to *s1 do
  34.      insert(names1,name(s1[i]) ? (tab(upto('.')),=".",tab(0)))
  35. every write(!names1)
  36. names2:=set()
  37. every i := 1 to *s2 do
  38.      insert(names2,name(s2[i]) ? (tab(upto('.')),=".",tab(0)))
  39.  
  40. # Now copy the components with shared names
  41.  
  42. every n := !(names1**names2) do
  43.     s1[n] := s2[n]
  44. end
  45.